﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DDMedlem.Buisness.Rapportering;
using System.Data;
using System.IO;


namespace DDMedlem.Data
{
    public static class Export
    {
        public static void ExporterListe(DataSet dataset)
        {

            //DirectoryInfo di = Directory.CreateDirectory("exsport");
            StreamWriter writer = new StreamWriter(HttpContext.Current.Server.MapPath("/export/" + HttpContext.Current.Session["username"] + ".csv"), false, System.Text.Encoding.UTF8);

            //writer = File.CreateText(HttpContext.Current.Server.MapPath("/export/"+HttpContext.Current.Session["username"]+".csv"));
            
            if (dataset != null)
            {
                writer.WriteLine("Eksporteret liste:\n\n");
                for (int i = 0; i < dataset.Tables[0].Columns.Count; i++)
                {
                    writer.Write(dataset.Tables[0].Columns[i].ToString()+"; ");
                }
                writer.WriteLine();
                for (int i = 0; i < dataset.Tables.Count; i++)
                {
                    for (int j = 0; j < dataset.Tables[i].Rows.Count; j++)
                    {
                        for (int k = 0; k < dataset.Tables[i].Columns.Count; k++)
                        {
                            writer.Write(dataset.Tables[i].Rows[j][k].ToString() + "; ");
                        }
                        writer.WriteLine();
                    }
                }
            }
            writer.Close();
        }
    }
}